package com.byl.mvvm.ui.main


import android.app.Activity
import android.content.Intent
import com.byl.mvvm.App
import com.byl.mvvm.databinding.ActivityTestEventBinding
import com.byl.mvvm.event.EventCode
import com.byl.mvvm.event.EventMessage
import com.byl.mvvm.ui.base.BaseActivity
import com.byl.mvvm.ui.base.BaseViewModel
import com.byl.mvvm.utils.ToastUtil
import com.byl.mvvm.widget.clicks


class TestEventActivity : BaseActivity<BaseViewModel, ActivityTestEventBinding>() {

    override fun initView() {


    }

    override fun initClick() {
        v.btn.clicks {
            App.post(EventMessage(EventCode.REFRESH))

            val intent = Intent().apply {
                putExtra("result", "二级页面回传数据")
            }

            setResult(Activity.RESULT_OK, intent)
            finish()
        }
    }

    override fun initData() {

        val name = intent.getStringExtra("name")
        ToastUtil.showToast(mContext, "接收到的数据：${name}")
    }

    override fun initVM() {

    }

    override fun handleEvent(msg: EventMessage) {
        super.handleEvent(msg)
        if (msg.code == EventCode.CONFRIM) {
            ToastUtil.showToast(mContext, "我知道了")
        }
    }
}